<?php
date_default_timezone_set('PRC');
function php_check_syntax($file,&$error) {
  exec("php -l $file",$error,$code);
  if($code == 0)
    return true;
  return false;
}

//$r = check_syntax('/data/htdocs/deployer.abcabc.com','php',$out);
function check_syntax($dir,$lang,&$out){
  if(!is_dir($dir)) return false;
  $ret = true;
  $dh = opendir($dir);
  while ($file = readdir($dh)) {
    if($file != "." && $file != "..") {
      $fullpath = $dir."/".$file;
      if(is_file($fullpath)){
		$ext = '';
		$temparr1 = explode('.',$file);
		if(count($temparr1) > 0){
			$last = count($temparr1)-1;
			$ext = $temparr1[$last];
		}

      	if($ext == $lang){
      		//echo $fullpath.PHP_EOL;
      		$func = $lang.'_check_syntax';
      		$r = $func($fullpath,$error);
      		if(!$r) {
      			$ret = false;
      			$out[] = $error;
      		}
      	}
      }elseif(is_dir($fullpath)){
      		$r = check_syntax($fullpath,$lang,$out);
      		if(!$r) {
      			$ret = false;
      			$out[] = $error;
      		}
      }


    }
  }
  closedir($dh);
  return $ret;
}
